package com.lzb.permanentcalendar.utils;


import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;

import androidx.core.app.NotificationCompat;

import com.lzb.permanentcalendar.R;


public class MyReceiver {
    private static final String CHANNEL_ID = "my_channel";
    public static int NOTIFICATION_ID = 101;

    public static void createNotificationChannel(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            CharSequence name = "My Channel";
            String description = "This is my notification channel";
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
            NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
            channel.setDescription(description);

            NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
            notificationManager.createNotificationChannel(channel);
        }
    }

    public static void showNotification(Context context, String kk, boolean f1) {
        int flag = f1 ? Notification.DEFAULT_SOUND : Notification.DEFAULT_VIBRATE;
        // 获取默认通知声音的Uri
        Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
                .setContentTitle("通知")    //设置标题
                .setContentText(kk)    //设置通知文字
                .setWhen(System.currentTimeMillis()) //时间
                .setSmallIcon(R.drawable.ic_launcher_background)   //设置左边的小图标
//                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.message))  //设置大图标
                .setDefaults(flag); //添加默认震动、声音、三色灯三种提醒


        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(NOTIFICATION_ID, builder.build());
    }

}
